<template>
  <div class="Login_container">
    <div class="text">
      <h1>学生成绩管理系统登录界面</h1>
    </div>
    <div class="text2">
      <h1>毕业设计 -李子彬</h1>
    </div>
    <div class="text3">
      <h1><a href="http://www.lizibin.top" target="_blank">个人博客地址</a></h1>
    </div>
    <div class="Login_box">
      <!--头像-->
      <div class="avater_box">
        <img src="../assets/img/tou.png" alt="">
      </div>
      <!--表单-->
      <el-form ref="LoginFormRef" :model="LoginForm" :rules="LoginFormRules" label-width="80px" class="form">
        <!--用户名-->
        <el-form-item label="用户名:" prop="username">
          <el-input placeholder="Username" v-model="LoginForm.username"></el-input>
        </el-form-item>
        <!--密码-->
        <el-form-item label="密码:" prop="password">
          <el-input type="password" placeholder="Password" v-model="LoginForm.password"></el-input>
        </el-form-item>
        <!--按钮-->
        <el-form-item class="box_but">
          <el-button type="primary" @click="login">登录</el-button>
          <el-button type="info" @click="reset">重置</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      // 登录表单绑定数据对象
      LoginForm: {
        username: '',
        password: ''
      },
      // 验证用户名，密码
      LoginFormRules: {
        username: [
          { required: true, message: '请输入用户名', trigger: 'blur' },
          { min: 3, max: 10, message: '用户名长度在3-10个字符', trigger: 'blur' }
        ],
        password: [
          { required: true, message: '请输入密码', trigger: 'blur' },
          { min: 6, max: 15, message: '密码长度为6-15个字符', trigger: 'blur' }
        ]
      }
    }
  },
  methods: {
    reset() {
      this.$refs.LoginFormRef.resetFields()
    },
    login() {
      this.$refs.LoginFormRef.validate(async valid => {
        if (!valid) return
        const { data: res } = await this.$http.post('login', this.LoginForm)
        if (res === 1) return this.$message.error('用户名或密码错误！')
        this.$message.success('登录成功，欢迎！')
        this.$router.push('/home')
      })
    }
  }
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style lang="less" scoped>
.Login_container {
  background-color: #2b4b6b;
  height: 100%;
}

.Login_box {
  width: 450px;
  height: 300px;
  background-color: #fff;
  border-radius: 3px;
  position: absolute;
  left: 50%;
  top: 60%;
  transform: translate(-50%,-50%);

  .avater_box {
    height: 130px;
    width: 130px;
    border: 1px solid #eee;
    border-radius: 50%;
    padding: 10px;
    box-shadow: 0 0 10px #ddd;
    position: absolute;
    left: 50%;
    transform: translate(-50%,-50%);
    background-color: #fff;
    img {
      width: 100%;
      height: 100%;
      border-radius: 50%;
      background-color: #eee;
    }
  }
}
.box_but {
  display: flex;
  justify-content: flex-end;
}
.form {
  position: absolute;
  bottom: 0;
  width: 80%;
  padding: 0 10px;
}
.text {
  width: 650px;
  height: 80px;
  border: 1px solid;
  position: absolute;
  left: 50%;
  top: 10%;
  transform: translate(-50%);
  text-align: center;
  font-size: 25px;
  line-height: 25px;
  font-family: 宋体;
  box-shadow: 0 0 10px #eee;
  color:lightblue;
}
.text2 {
  position: absolute;
  left: 70%;
  top: 23%;
  transform: translate(-50%);
  text-align: center;
  font-size: 20px;
  line-height: 20px;
  font-family: 宋体;
  color:lightblue;
}
.text3 {
  position: absolute;
  left: 30%;
  top: 23%;
  transform: translate(-50%);
  text-align: center;
  font-size: 20px;
  line-height: 20px;
  font-family: 宋体;
  a {
    color:lightblue;
  }
}
</style>
